package com.example.demo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.demo.mapper.NewsMapper;
import com.example.demo.model.entity.NewsEntity;
import com.example.demo.model.param.NewsParam;
import com.example.demo.model.param.PageParam;
import com.example.demo.model.vo.ResponseVo;
import com.example.demo.service.NewsService;
import com.example.demo.service.impl.NewsServiceImpl;
import com.example.demo.untils.BuildResponseUtils;
import com.example.demo.untils.CommonQueryPageUntils;
import com.example.demo.untils.PageBean;
import com.example.demo.untils.PageVoUtils;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class NewsController {


    @Autowired
    private NewsService newsService;


    @PostMapping("/addNews")
    public ResponseVo<?> addNews(@RequestBody NewsEntity newsEntity){
        return newsService.save(newsEntity) ? BuildResponseUtils.success():BuildResponseUtils.error();
    }


    @PostMapping("/listNews")
    public ResponseVo<?> listNews(@RequestBody NewsParam newsParam){
        PageInfo pageInfo = newsService.selectNewsList(newsParam);
        PageBean pageBean = PageVoUtils.convertTopageVo(pageInfo);
        return BuildResponseUtils.buildResponse(pageBean);
    }


    @PostMapping("/updateNews")
    public ResponseVo<?> updateNews(@RequestBody NewsEntity newsEntity){
        return newsService.updateById(newsEntity)? BuildResponseUtils.success():BuildResponseUtils.error();
    }
}
